﻿using System.Collections.Generic;

namespace Our.Umbraco.uDbCompare
{
    public class BaseQueryItem
    {
        public int Id { get; set; }

        // These are the old query struct fields
        public LinkItem linkItem { get; set; }
        public string linkIdField { get; set; }
        public string key { get; set; }
        public List<string> fields { get; set; }
        public string select { get; set; }
        public string childKey { get; set; }
        public bool childKeyContainsDelimiter { get; set; }
        public List<string> childFields { get; set; }
        public bool createChildren { get; set; }

        /// <summary>
        /// Return a url to link to an item in the umbraco system.
        /// Deeplinking is used when possible, however, in cases where the id is not passed as id in the url, 
        /// then it will not work (for example, template needs templateid)
        /// </summary>
        /// <param name="linkItem"></param>
        /// <param name="id"></param>
        /// <param name="remote"></param>
        /// <returns></returns>
        protected string GetLinkUrl(bool remote, string urlFormatString)
        {
            string url = string.Empty;
            string baseUrl = string.Empty;
            if (remote)
            {
                baseUrl = uDbCompareCMSNode.GetValidHref(SessionVars.NodeId);

                // If we can't find the url, just return an empty string
                if (string.IsNullOrEmpty(baseUrl))
                    return string.Empty;
            }

            // TODO: Can we detect if the plugin exists first?
            // direct link
            url = string.Format(urlFormatString, baseUrl, Id);

            return url;
        }

    }
}